package com.toprs.base.controller

import com.toprs.base.entity.Dept
import com.toprs.base.entity.DeptManager
import com.toprs.base.result.Result
import com.toprs.base.service.DeptService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.validation.Valid
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/dept")
@Tag(description = "部门管理", name = "部门管理")
class DeptController(val deptService: DeptService) {


    @PostMapping("/addDept")
    @Operation(summary = "添加部门")
    fun addDept(@Valid @RequestBody dept: Dept): Result<Unit> {
        deptService.addDept(dept)
        return Result.successMsg("添加成功！")
    }


    @GetMapping("/list")
    @Operation(summary = "获取部门列表")
    fun getDeptList(): Result<List<Dept>> {
        return Result.success(deptService.getDeptList())
    }

    @PutMapping("/setManager")
    @Operation(summary = "设置部门管理人员")
    fun setManager(@Valid @RequestBody deptManager: DeptManager): Result<Unit> {

        deptService.setManager(deptManager)
        return Result.successMsg("设置成功")
    }


    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除部门")
    fun deleteDept(@PathVariable id: Int): Result<Unit> {
        deptService.deleteDept(id)
        return Result.successMsg("删除部门成功")
    }


    @PostMapping("/edit")
    @Operation(summary = "编辑部门信息")
    fun editDept(@Valid @RequestBody dept: Dept): Result<Unit> {
        deptService.editDept(dept)
        return Result.successMsg("编辑部门成功")
    }


}